package com.fyy.kafuka.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @Author fyy
 * @Description
 * @Date 2020/11/6 15:58
 */
public class AddTimeInterceptor implements ProducerInterceptor<String,String> {

    //在数据发送前处理数据，但是不建议修改分区
    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        ProducerRecord<String, String> record1 = new ProducerRecord<String, String>(record.topic(),
                record.partition(),record.key(),System.currentTimeMillis()+record.value());
        return record1;
    }

    @Override
    public void onAcknowledgement(RecordMetadata recordMetadata, Exception e) {

    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
